import time
import json

'''
行政处罚
'''


def get_punish_info(mongo_instance, soup, cid, company):
    print('start 行政处罚数据*******')
    for tr in soup.find('div', id='_container_punish').find('tbody').find_all('tr') if soup.find('div',
                                                                                                 id='_container_punish') else []:
        item = {}
        tds = tr.find_all('td')
        if len(tds) > 4:
            script = tds[5].find('script')
        else:
            script = tds[3].find('script')
        item = json.loads(script.text)
        item['details'] = script.text
        item['create_at'] = int(time.time())
        item['update_at'] = item['create_at']
        item['company'] = company
        item['company_id'] = cid
        print(item)
        mongo_instance.punish.update({'company_id': cid}, item, True)
    print('success 行政处罚数据*******')
